#define _CRT_SECURE_NO_WARNINGS 1
#include"string.h"

namespace x {
	ostream& operator<<(ostream& out, const string& s)
	{
		for (auto ch : s)
		{
			out << ch;
		}
		return out;
	}

	string& string::operator+=(char c)
	{
		if (_size == _capacity)
		{
			_capacity = _capacity == 0 ? 4 : 2 * _capacity;
		}
		char* tmp = new char[_capacity+1];
		strcpy(tmp, _str);
		delete[] _str;
		_str = tmp;
		_str[_size++] = c;
		_str[_size] = '\0';
		return *this;
	}

	istream& operator>>(istream& in,string& s)
	{
		char ch;
		ch = in. get();
		while (ch != ' ' && ch != '\n')
		{
			s += ch;
			ch = in.get();
		}
		return in;
	}

	void test_string()
	{
		string s1("abc");
		string s2(s1);
		string s3 = s2;
		cout << s1.c_str() << endl;
		cout << s2.c_str() << endl;
		cout << s3.c_str() << endl;
		cin >> s1;
		cout << s1.c_str() << endl;
	}
}